package sxe.core.hash;

import java.sql.SQLException;
import snobject.snBoolean;
import snobject.snObject;
import snobject.snObjectArgList;
import step.EvaluationFailure;
import step.FunctionWrapper;
import step.exceptions.ResourceUnavailableException;
import sxe.core.EvaluationFailureReasons;

public class contains extends FunctionWrapper {

	@Override
	public snObject Call(snObjectArgList argv) throws EvaluationFailure,
			ClassCastException, ArrayIndexOutOfBoundsException,
			ResourceUnavailableException {
		
		snObject value = null;

		if(argv.length()<1)
			throw new EvaluationFailure(super.expnode,
					EvaluationFailureReasons.BAD_PARAMETER_COUNT);

		String key = argv.popString().getString();

		try{
			value = SQLClientInstance.getInstance().Get(key);
			if (value==null) 
				return new snBoolean(false);
			return new snBoolean(true);
		}
		catch(SQLException sqe){
			sqe.printStackTrace();
			throw new ResourceUnavailableException("SQLException in put: " + sqe.getMessage());
		}
	}

}
